<?php

namespace app\api\model;

use think\Model;

class SeparateSet extends Model
{
    protected $name = 'separate_set';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';
    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (empty($row['secret'])) {
                $pk = $row->getPk();
                $row->getQuery()->where($pk, $row[$pk])->update(['secret' => uniqid((string)$pk)]);
            }
        });
    }
}